<template>
	<view class="content wrap">
		<u-form :model="form" ref="uForm" :rules="rules">

			<u-form-item label="操作类型" label-width="150">
				<u-radio-group v-model="form.operationType">
					<u-radio @change="radioChange" v-for="(item, index) in worklist" :key="index" :name="item.name">
						{{item.name}}
					</u-radio>
				</u-radio-group>
			</u-form-item>

			<u-form-item label="仓库" label-width="150" prop="warehouseName">
				<u-input v-model="form.warehouseName" placeholder="请输入收货仓库" />
			</u-form-item>

			<u-form-item label="司机姓名" label-width="150" prop="driverName">
				<u-input v-model="form.driverName" placeholder="请输入司机姓名" />
			</u-form-item>

			<u-form-item label="司机手机号" label-width="150" prop="tel">
				<u-input v-model="form.tel" type="digit" placeholder="请输入司机手机号" />
			</u-form-item>

			<u-form-item label="车牌号" label-width="150" prop="carNumber">
				<u-input v-model="form.carNumber" placeholder="请输入车牌号" />
			</u-form-item>

		</u-form>
		<view>
			<u-form-item>
			</u-form-item>
		</view>
		<u-button @click="clockin" type="primary">提交</u-button>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					warehouseName: "", //发货仓库
					customerName: "", //收货门店
					driverName: "", //司机姓名
					tel: "", //司机手机号
					carNumber: "", //车牌号
					operationType: "门店出库", //操作类型
				},
				scanneal: [],
				worklist: [{
						name: '门店出库'
					},
				],
			};
		},
		onLoad: function(open) {
			var packNumber = uni.getStorageSync("packNumber");
			this.scanneal = packNumber;
		},
		methods: {
			clockin() {

				// 如果是门店出库且门店名称为空，则不执行校验
				if (this.operationType === '门店出库' && (typeof this.form.customerName === 'undefined' || this.form
						.customerName === null || this.form.customerName === '')) {
					return true; // 不执行校验，直接返回 true
				}
				if (typeof this.form.driverName == 'undefined' || this.form.driverName == null || this.form.driverName ==
					'') {
					uni.showToast({
						title: '请输入司机姓名',
						duration: 2000,
						icon: 'none',
					});
					return false;
				}
				if (typeof this.form.tel == 'undefined' || this.form.tel == null || this.form.tel == '') {
					uni.showToast({
						title: '请输入司机手机号',
						duration: 2000,
						icon: 'none',
					});
					return false;
				}
				if (typeof this.form.carNumber == 'undefined' || this.form.carNumber == null || this.form.carNumber ==
					'') {
					uni.showToast({
						title: '请输入车牌号',
						duration: 2000,
						icon: 'none',
					});
					return false;
				}
				uni.showLoading({
					title: '正在提交'
				})

				this.$http.post('/rest/hxzhouzhuan/turnoverContainerf?packNumbers=' + this.scanneal, {}, {
					params: this.form,
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '操作成功',
							type: 'success'
						})
   
						setTimeout(() => {
							this.$Router.push({
								name: 'turnover_container_md',
							})
						}, 100)
					}
				})
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.wrap {
		padding: 30rpx;
	}
</style>